﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DXWindowsApplication3.DTO;
using System.Data.SqlClient;

namespace DXWindowsApplication3.GUI
{
    public partial class LOGIN : Form
    {
        public LOGIN()
        {
            InitializeComponent();
        }
        void LoginU()
        {
            USER u = new USER();
            string username = txtUserName.Text;
            string pwd = txtPwd.Text;
            string sql = string.Format("select t.*,c.TENCHUCVU from TAIKHOAN t, CHUCVU c where USERNAME = '{0}' and t.MACV = c.MACV", username);//lay ra 1 dong theo username
            SqlConnection cn = DataProvider.ConnectionData();
            SqlCommand cmd = new SqlCommand(sql, cn);
            SqlDataReader dr;
            dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                u.Password = dr["Password"].ToString();
                USER.TenChucVu = dr["TenChucVu"].ToString();
                //user name duoc lay tu textbox
            }
            if (u.Password != pwd)
            {
                MessageBox.Show("Đăng nhập thất bại", "Thông báo", MessageBoxButtons.OK);
                return;
            }
            else
            {
                USER.KT = true;
                USER.UserName = username;
                Form1 f = new Form1();
                f.ShowDialog();
            }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            LoginU();
        }

        private void LOGIN_Load(object sender, EventArgs e)
        {

        }
    }
}
